package com.example.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;

import java.util.Random;

public class User2 implements InitializingBean {
    private Long id;
    private String name;
    private Integer traceId;


    public User2(Long id, String name) {
        System.out.println("User2 Bean完成：实例化");
        this.id = id;
        this.name = name;
        System.out.println("User2 Bean完成：属性注入");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("User2 Bean开始：初始化");
        this.traceId = new Random().nextInt();
        System.out.println("User2 Bean完成：初始化");
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getTraceId() {
        return traceId;
    }

    public void setTraceId(Integer traceId) {
        this.traceId = traceId;
    }
}
